/**
 * 
 */
package org.vsg.stock.dzh;

import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.vsg.stock.basic.persistence.StockDailyLineDao;
import org.vsg.stock.basic.persistence.StockInfoDao;

/**
 * @author vison
 *
 */
public class UpdateAllStockDailyLineExRights {

	private final static Logger logger = LoggerFactory.getLogger(GenerateDailyLine.class);	


	public void exec(ApplicationContext appContext) throws Exception {
		
		StockInfoDao stockInfoDao = (StockInfoDao)appContext.getBean("stockInfoDao");
		
		StockDailyLineDao stkDailyLineDao = (StockDailyLineDao)appContext.getBean("stockDailyLineDao");
		
		List<String> allStkInfo = stockInfoDao.findAllCode();
		
		String stkCode = null;
		for (Iterator<String> allStkInfoIter = allStkInfo.iterator() ; allStkInfoIter.hasNext(); ) {
			stkCode = allStkInfoIter.next();
			
			stkDailyLineDao.updateStockExRights(stkCode);
			
		}

		logger.info("update ex rights !");
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ClassLoader clsLoader = GenerateDailyLine.class.getClassLoader();
		// --- run the main page ---
		// build the read the path , dzh's home path
		String[] configContextFiles = {
				"classpath:/spring/configurationContext.xml",
				"classpath*:/spring/applicationContext.xml",
				"classpath*:/spring/dataAccessContext.xml"
		};
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext(configContextFiles,true);
	
		UpdateAllStockDailyLineExRights mainProg = new UpdateAllStockDailyLineExRights();
		
		try {
			mainProg.exec(ctx);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		logger.info("program run ... Ok!");
	}

}
